﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FingerPrintRecognizer.Common;

namespace FPRAdminClient
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();            
        }

        private void loginBtn_Click(object sender, EventArgs e)
        {
            if (this.User.Text == "")
                MessageBox.Show("Enter Username","Username is required");
            else if (this.Password.Text == "")
                MessageBox.Show("Enter Password", "Password is required");
            else
            {
                FPRecognizerServiceClient client = new FPRecognizerServiceClient();
                string access_token = client.getAccessToken(this.User.Text, this.Password.Text);
                if (access_token == null)
                {
                    MessageBox.Show("Authentication Failed, Please check your username & password", "Authentication Failed");
                }
                else
                {
                    Main mainWindow = new Main();
                    mainWindow.Show();
                    this.Hide();
                }
            }                                    
        }

        private void ExitBtn_Click(object sender, EventArgs e)
        {
            DialogResult msg_result = MessageBox.Show("Do you really want to exit ? ","Exit",MessageBoxButtons.YesNo);
            if (msg_result == DialogResult.Yes)    
                Environment.Exit(0);  
        }

        private void LoginForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

    }
}
